<script setup>
import { ref, onMounted } from 'vue';
import { queryLogApi } from '@/api/report';
import { ElMessage } from 'element-plus';

// 日志数据
const logData = ref([]);
const page = ref(1)
const pageSize = ref(10)
const total = ref();

//钩子函数
onMounted(async() => {
  search();
})

//页码改变触发
const handleCurrentChange = (val) => {
  page.value = val;
  search();
}
//页面记录条数改变触发
const handleSizeChange = (val) => {
  pageSize.value = val;
  search();
}

//查询
const search = async () => {
  const result = await queryLogApi(page.value, pageSize.value);
  if (result.code ) {
    total.value = result.data.total;
    logData.value = result.data.rows;
  } else {
    ElMessage.error(result.msg);
  }
}

</script>

<template>
  <h1>日志管理</h1>
  <!-- 表格内容 -->
  <div class="container">
    <el-table :data="logData" border style="width: fit-content">
      <el-table-column prop="operateEmpName" label="操作人" width="100" align="center" />
      <el-table-column prop="operateTime" label="操作时间" width="170" align="center" />
      <el-table-column prop="className" label="类名" width="320" align="center" />
      <el-table-column prop="methodName" label="方法名" width="120" align="center" />
      <el-table-column prop="costTime" label="操作耗时(ms)" width="120" align="center" />
      <el-table-column prop="methodParams" label="请求参数" width="300" show-overflow-tooltip align="center">
        <template #default="scope">
          <el-tag style="max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: middle; line-height: 1.2;padding: 4px 8px;">{{ scope.row.methodParams }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="returnValue" label="返回值" width="320" align="center" />
    </el-table>
  </div>

  <!-- 分页 -->
  <div class="container">
    <el-pagination
      v-model:current-page="page"
      v-model:page-size="pageSize"
      :page-sizes="[10, 20, 30, 50, 75, 100, 200]"
      background="true"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<style scoped>
.container {
  margin: 15px 0;
}
</style>